﻿/**
 *
 * master.h
 *
 *  Created on: 2019-05-05
 *      Author: chenshisheng
 */

#ifndef MASTER_H_
#define MASTER_H_

#include "main.h"
#include "serial.h"

typedef enum
{
    Master_State_Idle = 1,
    Master_State_Rxing,
    Master_State_FrameIn,
    Master_State_FrameError,
    Master_State_Timeout,
}Master_State_t;

typedef bool (*Master_FrameCheck_t)(const void *frame, unsigned int size);

typedef struct
{
    Serial_t serial;
    uint8_t head;
    unsigned int size;
    unsigned int timeout;
    Master_FrameCheck_t check;
}Master_Rx_t;

void Master_Init(void);
void Master_StartRx(const Master_Rx_t *rx);
void Master_StopRx(void);
Master_State_t Master_State(void);
int Master_RxBufferRead(unsigned int offset, void *dataOut, unsigned int size);
unsigned int Master_RxSize(void);
void Master_SetRxBufferOffset(unsigned int offset);
int Master_RxBufferTake(void *dataOut, unsigned int size);

#endif /* MASTER_H_ */
